//
//  visiterView.swift
//  weibo10
//
//  Created by 晁岳山 on 15/10/15.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit
import SnapKit
/// MARK - 访客视图 处理未登录界面

class visiterView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        //界面布局
        setupUI()
        //设置代理
       
    }

    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
/// 在不同的界面上显示不同的内容  只要重写这个方法就可以啦
    func showMessage(imageName: String?, content: String?) {
        
        //如果图片是nil 说明是首页  直接返回就行啦
        guard let imgname = imageName, text = content else {
            startAnimation()
            return
        }
        iconImageView.image = UIImage(named: imgname)
        messageLabel.text = text
        //让小房子隐藏
        houseImageView.hidden = true
        //让遮罩层隐藏  或者 移动到最下面
        corverImageView.hidden = true
        //或者移动到下面
//        sendSubviewToBack(corverImageView)
    }
    
    //设置动画
    func startAnimation() {
        let animation = CABasicAnimation(keyPath: "transform.rotation")
        animation.toValue = 2 * M_PI
        animation.repeatCount = MAXFLOAT
        animation.duration = 20
        animation.removedOnCompletion = false
        iconImageView.layer.addAnimation(animation, forKey: nil)
    }
    
    //创建需要的空间
    
    //1.图标
    private lazy var iconImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    //6.添加遮罩层
    private lazy var corverImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //2.小房子
    private lazy var houseImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //3.消息文字
    private lazy var messageLabel: UILabel = UILabel(content: "关注一些人，回这里看看有什么惊喜")
    //4.注册按钮
    lazy var registerBtn: UIButton = UIButton(backImageName: "common_button_white_disable", btnName: "注册", color: UIColor.orangeColor())
//    //登录按钮
    lazy var loginBtn: UIButton = UIButton(backImageName: "common_button_white_disable", btnName: "登录")
    //添加监听方法
}

// MARK: - 界面的布局
extension visiterView {
    func setupUI() {
        //添加控件到父控件
        addSubview(iconImageView)
        addSubview(corverImageView)
        addSubview(houseImageView)
        addSubview(messageLabel)
        addSubview(registerBtn)
        addSubview(loginBtn)
        
        //利用第三方框架设置布局
        
        //1.图标
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-60)
        }
        //2.小房子
        houseImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(iconImageView.snp_center)
        }
        //3.消息文字
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImageView.snp_centerX)
            make.top.equalTo(iconImageView.snp_bottom).offset(16)
            make.width.equalTo(224)
            make.height.equalTo(36)
        }
        //4.按钮
        registerBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(messageLabel.snp_left)
            make.bottom.equalTo(messageLabel.snp_bottom).offset(50)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        //5.登录按钮
        loginBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(registerBtn.snp_right).offset(30)
            make.bottom.equalTo(messageLabel.snp_bottom).offset(50)
            make.width.equalTo(100)
            make.height.equalTo(36)
        }
        //设置遮罩层
        corverImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(registerBtn.snp_bottom).offset(-36)
        }
        //设置背景颜色
        backgroundColor = UIColor(white: 237.0/255.0, alpha: 1.0)
    }
}






